package com.kgc.app.service.impl;

import com.kgc.app.mapper.DataDictionaryMapper;
import com.kgc.app.pojo.DataDictionary;
import com.kgc.app.pojo.DataDictionaryExample;
import com.kgc.app.service.DataDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DataDictionaryServiceImpl implements DataDictionaryService {

    @Autowired
    private DataDictionaryMapper dataDictionaryMapper;


    @Override
    public List<DataDictionary> selectDataByTypeName(String typeName) {

        DataDictionaryExample dataDictionaryExample = new DataDictionaryExample();
        DataDictionaryExample.Criteria criteria = dataDictionaryExample.createCriteria();

        criteria.andTypeNameEqualTo(typeName);

        List<DataDictionary> list = dataDictionaryMapper.selectByExample(dataDictionaryExample);

        return list;
    }

    @Override
    public DataDictionary selectByTypeNameAndValueId(String typeName, Long valueId) {

        DataDictionaryExample dataDictionaryExample = new DataDictionaryExample();
        DataDictionaryExample.Criteria criteria = dataDictionaryExample.createCriteria();
        criteria.andValueIdEqualTo(valueId);
        criteria.andTypeNameEqualTo(typeName);

        List<DataDictionary> list = dataDictionaryMapper.selectByExample(dataDictionaryExample);

        return list.get(0);
    }
}
